package com.five.wisdomEat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.five.wisdomEat.entity.Dishes;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishesMapper extends BaseMapper<Dishes>{
    //查询商家所有菜品信息
    @Select("SELECT d.*,dt.dt_name,ds.ds_name,b.b_name FROM dishes d " +
            "INNER JOIN dishes_type dt ON d.d_typeId = dt.id " +
            "INNER JOIN dishes_state ds ON d.d_stateId = ds.id" +
            "INNER JOIN businessinfo b ON d.d_b_number = b.b_number" +
            "WHERE b_number = #{bNumber}")
    List<Dishes> selectDishesList(String bNumber);

    //添加菜品
    @Insert("INSERT INTO dishes " +
            "(id,d_number,d_name,d_typeId,d_price,d_count,d_weight,d_photo,d_stateId) " +
            "VALUES (null,#{dNumber},#{dName},#{dTypeId},#{dPrice},#{dCount},#{dWeight},null,1)")
    Integer insertDishes(Dishes dishes);


    //根据菜品编号修改菜品信息
    @Update("UPDATE dishes SET d_name=#{dName},d_typeId=#{dTypeId},d_price=#{dPrice},d_count=#{dCount},d_weight=#{dWeight}" +
            " WHERE d_number = #{dNumber}")
    Integer updateDishes(Dishes dishes);

    //上架菜品
    @Update("UPDATE dishes SET d_stateId = 1 WHERE d_number = #{dNumber}")
    Integer onSaleDishes(String dNumber);

    //下架菜品
    @Update("UPDATE dishes SET d_stateId = 2 WHERE d_number = #{dNumber}")
    Integer offShelfDishes(String dNumber);

    //根据菜品编号删除菜品
    @Delete("DELETE FROM dishes WHERE d_number = #{dNumber}")
    Integer deleteDishes(String dNumber);

    //不定查询
    @Select("SELECT d.*,dt.dt_name,ds.ds_name,b.b_name FROM dishes d " +
            "INNER JOIN dishes_type dt ON d.d_typeId = dt.id " +
            "INNER JOIN dishes_state ds ON d.d_stateId = ds.id" +
            "INNER JOIN businessinfo b ON d.d_b_number = b.b_number" +
            "WHERE d.d_b_number = #{bNumber}" +
            "AND d.d_number like #{dNumber}" +
            "AND d.d_name like #{dName}" +
            "AND (d.d_stateId = #{dStateId} OR #{dStateId}<0)" +
            "AND (d.d_typeId = #{dTypeId} OR #{dTypeId}<0)")
    List<Dishes> selectDishesListByExample(Dishes dishes);


}
